<?php
defined('_JEXEC') or die;

class BakerysHelper
{

	public static function addSubmenu($vName = 'bakerys')
	{
		JHtmlSidebar::addEntry(
			JText::_('COM_BAKERYS_LOCATIONS'),
			'index.php?option=com_bakerys&view=bakerys',
			$vName == 'bakerys'
		);
		JHtmlSidebar::addEntry(
			JText::_('COM_BAKERYS_CATEGORIES'),
			'index.php?option=com_categories&extension=com_bakerys',
			$vName == 'categories'
		);
		
		JHtmlSidebar::addEntry(
			JText::_('COM_BAKERYS_ITEMS'),
			'index.php?option=com_bakerys&view=items',
			$vName == 'items'
		);			
		
		JHtmlSidebar::addEntry(
			JText::_('COM_BAKERYS_ORDERS'),
			'index.php?option=com_bakerys&view=orders',
			$vName == 'orders'
		);	
		
		if ($vName == 'categories')
		{
			JToolbarHelper::title(
				JText::sprintf('COM_CATEGORIES_CATEGORIES_TITLE', JText::_('com_weblinks')),
				'weblinks-categories');
		}
	}
	
	public static function getActions($categoryId = 0)
	{
		$user	= JFactory::getUser();
		$result	= new JObject;

		if (empty($categoryId))
		{
			$assetName = 'com_bakerys';
			$level = 'component';
		}
		else
		{
			$assetName = 'com_bakerys.category.'.(int) $categoryId;
			$level = 'category';
		}

		$actions = JAccess::getActions('com_bakerys', $level);

		foreach ($actions as $action)
		{
			$result->set($action->name,	$user->authorise($action->name, $assetName));
		}

		return $result;
	}

}
